<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/tentime">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
    <style>
        .layui-form-mid_ {
            position: relative;
            float: left;
            display: block;
            padding: 5px 0 !important;
            line-height: 20px;
            margin-right: 10px;
        }
        .tentime-compile .layui-input-inline {
            width: 150px !important;
        }
        .tentime-compile .tentime-finally {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background-color: #ffffff;
            height: 35px;
            border-top: 1px solid #ddd;
            padding: 5px 0 0 0!important;
            margin: 0px 10px 0px!important;
        }
    </style>
</head>
<body>
<div class="layui-form tentime-compile">
    <form id="inputForm" th:object="${entity}" class="layui-form"> <!-- th:action="@{/system/dept/save}" -->
        <input id="id" type="hidden" name="id" th:if="${entity}" th:value="${entity.id}"/>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">租户ID:</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid_" th:text="${entity.tenantId}"></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">租户名称:</label>
                <div class="layui-input-inline" style="width: 250px!important;">
                    <div class="layui-form-mid_" th:text="${entity.tenantName}"></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">连接用户:</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid_" th:text="${entity.username}"></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">连接密码:</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid_" th:text="${entity.password}"></div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">URL:</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid_" th:text="${entity.url}"></div>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">建库SQL:
                <a class="layui-btn layui-btn-xs layui-btn-primary" style="border: none" onclick="inpand('sqlCreate',this);">-收缩</a>
            </label>
            <div class="layui-input-block">
                <textarea id="sqlCreate" name="sqlCreate" th:utext="${entity?.sqlCreate}" autoHeight="true" style="width: 100%"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">初始SQL:
                <a class="layui-btn layui-btn-xs layui-btn-primary" style="border: none" onclick="inpand('sqlInit',this);">-收缩</a>
            </label>
            <div class="layui-input-block">
                <label style="color: red;">请务必修改管理员租户ID</label>
                <textarea id="sqlInit" name="sqlInit" th:utext="${entity?.sqlInit}" autoHeight="true" style="width: 100%"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">权限SQL:
                <a class="layui-btn layui-btn-xs layui-btn-primary" style="border: none" onclick="inpand('sqlGrant',this);">-收缩</a>
            </label>
            <div class="layui-input-block">
                <textarea id="sqlGrant" name="sqlGrant" th:utext="${entity?.sqlGrant}" autoHeight="true" style="width: 100%"></textarea>
            </div>
        </div>

        <div class="layui-form-item tentime-finally">
            <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="submit_button" shiro:hasAnyPermissions="masterTenat:init"><i class="fa fa-check-circle"></i> 保存</button>
            <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="closeWin();" type="button"><i class="fa fa-times-circle"></i> 关闭</button>
        </div>
    </form>
</div>
<script th:replace="/common/template :: common"></script>
<script type="text/javascript">
    layui.use(['form'/*,'layer','layedit', 'jquery'*/], function () {
        window.form = layui.form;
        //layer = layui.layer, $ = layui.jquery, layedit = layui.layedit;
        /*
        var index = layedit.build('sqlCreate', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right','|', 'table', 'fullScreen', 'preview']
            ,height: 100
        });
        var index1 = layedit.build('sqlGrant', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right','|', 'table', 'fullScreen', 'preview']
            ,height: 100
        });
         */
        // 初始化排序下拉选项
        form.on("submit(submit_button)", function (data) {
            /*
            var content = layedit.getContent(index), content1 = layedit.getContent(index1);
            $('#sqlCreate').text(content);
            $('#sqlGrant').text(content1);
            */
            $("#inputForm").ajaxSubmit({
                type : "post"
                ,url : ctx + '/masterTenant/initSql'
                ,success : function(data) {
                    var code = data.code;
                    if (code == 200) {
                        parent.layer.msg('数据保存成功!', {icon: 1});
                        closeWin();
                    } else {
                        parent.layer.msg('数据验证失败!', {icon: 2});
                    }
                }
            });
            return false;
        });
    });
    $(function() {//文本框高度自适应
        $.fn.autoHeight = function() {
            function autoHeight(elem) {
                elem.style.height = 'auto';
                elem.scrollTop = 0; //防抖动
                elem.style.height = elem.scrollHeight + 5 + 'px';
            }
            this.each(function() {
                autoHeight(this);
                $(this).on('keyup', function() {
                    autoHeight(this);
                });
            });
        }
        $('textarea[autoHeight]').autoHeight();
    });
    function inpand(id, e) {
        $('#' + id).toggle();
        var text = $(e).text();
        if (text === '-收缩') {
            $(e).text('+展开');
        } else if (text === '+展开') {
            $(e).text('-收缩');
        }
    }
</script>
</body>
</html>